<template>
  <div class="set-admin-works-add">
    <w-nav-bar
      :title="isEdit ? '编辑工作经历' : '添加工作经历'"/>
    <div class="w-flex-center image-box">
      <w-image-up
        ref="W_IMAGE_UP"
        :souce-url="model.icon"/>
    </div>
    <group>
      <x-input
        title="名称"
        placeholder="请输入名称"
        v-model="model.name"/>
      <datetime
        title="开始时间"
        placeholder="请选择时间"
        v-model="model.startTimeStr"/>
      <datetime
        title="结束时间"
        placeholder="请选择时间"
        v-model="model.endTimeStr"/>
      <x-input
        title="职责"
        placeholder="请输入职责"
        v-model="model.obligation"/>
      <x-textarea
        title="官网"
        placeholder="官网地址"
        v-model="model.url"/>
      <x-textarea
        title="说明"
        placeholder="请输入说明"
        v-model="model.detail"/>
    </group>
    <w-bottom-btn
      :model="model"
      :btn1-title="isEdit ? '删除' : ''"
      dispose-parameter1="name"
      @click2="okBtnClick"/>
  </div>
</template>

<script>
  import WorkModel from '@/models/web/WorkModel'
  import WImageUp from '@/components/global/imageUp/oss'
  import WBottomBtn from '@/components/mobile/confirmBottomBtn'
  import { Group, XInput, XTextarea, Datetime } from 'vux'
  export default {
    name: "SetAdminWorksAdd",
    components: {
      WImageUp,
      WBottomBtn,
      Group, XInput, XTextarea, Datetime
    },
    data() {
      return {
        /**
         * 模型数据
         */
        model: new WorkModel(),
        /**
         * 输入框时间
         */
        fieldDate: null
      }
    },
    computed: {
      /**
       * 是否是编辑模式
       */
      isEdit() {
        return this.$route.query.id
      }
    },
    methods: {
      /**
       * 获取详情数据
       */
      getDetail() {
        if (this.$route.query.id) {
          this.model._id = this.$route.query.id
          this.model.getDetail().w_then((data) => {
            this.fieldDate = data.dateStr
          })
        }
      },
      /**
       * 确定按钮点击
       */
      async okBtnClick(cellBack) {
        this.$w_check_form(this.model, [
          {
            key: 'name',
            msg: '请填写名称'
          }
        ], () => {
          this.$refs['W_IMAGE_UP'].upImage ().then((data) => {
            this.model.icon = data
            this.model.startTime = this.model.startTimeStr ? new Date(this.model.startTimeStr) : null
            this.model.endTime = this.model.endTimeStr ? new Date(this.model.endTimeStr) : null
            cellBack()
          }).catch(this.$w_error_pop)
        })
      }
    },
    mounted() {
      this.getDetail()
    }
  }
</script>

<style lang="scss" scoped>
  .set-admin-works-add {
    .image-box {
      padding-top: 10px;
    }
  }
</style>
